void portInit(){
    //按键
    PINSEL0 &= ~(0x03<<28);
    IO0DIR &= ~(0x01<<14);
    //led
    PINSEL0 &= ~(0x03<<0);
    PINSEL0 &= ~(0x03<<2);
    PINSEL0 &= ~(0x03<<4);
    PINSEL0 &= ~(0x03<<6);
    IO0DIR |= (0x01<<0);
    IO0DIR |= (0x01<<1);
    IO0DIR |= (0x01<<2);
    IO0DIR |= (0x01<<3);
}

void allLight(){
    portInit();
    while(1){
        if((IO0PIN&(0x01<<14))==0){
            IO0CLR |= (0x01<<0);
            IO0CLR |= (0x01<<1);
            IO0CLR |= (0x01<<2);
            IO0CLR |= (0x01<<3);
        }
        else{
            IO0SET |= (0x01<<0);
            IO0SET |= (0x01<<1);
            IO0SET |= (0x01<<2);
            IO0SET |= (0x01<<3);
        }
    }
}

void delayNS(uint32 dly){
    uint32 i;
    for(;dly>0;dly--)
        for(i=0;i<5000;i++);
}

void flicker(){
    portInit();
    while(1){
        if((IO0PIN&(0x01<<14))==0){
            IO0CLR |= (0x01<<0);
            IO0CLR |= (0x01<<1);
            IO0CLR |= (0x01<<2);
            IO0CLR |= (0x01<<3);
            delayNS(10);
            IO0SET |= (0x01<<0);
            IO0SET |= (0x01<<1);
            IO0SET |= (0x01<<2);
            IO0SET |= (0x01<<3);
            delayNS(10);
        }
        else{
            IO0SET |= (0x01<<0);
            IO0SET |= (0x01<<1);
            IO0SET |= (0x01<<2);
            IO0SET |= (0x01<<3);
        }
    }
}

void __irq EINT1_ISR(){
    if((IO0PIN&(0x01<<14))==0){
        IO0CLR |= (0x01<<0);
        IO0CLR |= (0x01<<1);
        IO0CLR |= (0x01<<2);
        IO0CLR |= (0x01<<3);
    }
    else{
        IO0SET |= (0x01<<0);
        IO0SET |= (0x01<<1);
        IO0SET |= (0x01<<2);
        IO0SET |= (0x01<<3);
    }
}


void EINT0_Init(){
    //EINT1
    PINSEL0 |= (0x02<<14);
    EXTMODE |= (0x01<<1);   //边沿触发
    EXTPOLAR|= (0x01<<1);   //上升沿中断

    VICIntSelect &= ~(0x01<<15);
    VICVectCntl0 = 0x20|15;
    VICVectAddr0 = (uint32)EINT1_ISR;

    VICIntEnable=(1<<15);
}